﻿using System;
using System.Runtime.Serialization;

namespace NetBay.Core.BusinessEntities.Versioning
{
    /// <summary>
    /// Represent a version item
    /// </summary>
    [DataContract]
    public class VersioningItem : ReturnObject
    {

        #region Attributs
        private int _major;
        private int _minor;
        #endregion

        #region Properties

        /// <summary>
        /// Get or Set the Major version number, IndexOutOfRangeException raised if number is less than zero.
        /// </summary>
        [DataMember]
        public int Major
        {
            get
            {
                return _major;
            }
            set
            {
                if (_major < 0)
                    throw new IndexOutOfRangeException("Major number cannot be less than zero.");
                else
                    _major = value;
            }
        }

        /// <summary>
        /// Get or Set the Minor version number, IndexOutOfRangeException raised if number is less than zero.
        /// </summary>
        [DataMember]
        public int Minor
        {
            get
            {
                return _minor;
            }
            set
            {
                if (_minor < 0)
                    throw new IndexOutOfRangeException("Minor number cannot be less than zero.");
                else
                    _minor = value;
            }
        }

        /// <summary>
        /// Get or set the version identifier
        /// </summary>
        [DataMember]
        public long VersionId { get; set; }

        /// <summary>
        /// Get a formated fullname
        /// </summary>
        [DataMember]
        public string FullVersion
        {
            get
            {
                return String.Format("{0}.{1}", Major, Minor);
            }
            set { }
        }

        /// <summary>
        /// version note
        /// </summary>
        [DataMember]
        public string Note { get; set; }

        /// <summary>
        /// version author
        /// </summary>
        [DataMember]
        public string Author { get; set; }

        /// <summary>
        /// version photo credit
        /// </summary>
        [DataMember]
        public string PhotoCredit { get; set; }

        /// <summary>
        /// Get or set version state
        /// </summary>
        [DataMember]
        public VersionState State { get; set; }

        /// <summary>
        /// Get or set a value that indicates whether the version is the current version.
        /// </summary>
        [DataMember]
        public bool IsCurrentVersion { get; set; }

        /// <summary>
        /// Get or set a value that indicates whether the version is the original version.
        /// </summary>
        [DataMember]
        public bool IsOriginalVersion { get; set; }

        /// <summary>
        /// Get or set the relative version path
        /// </summary>
        [DataMember]
        public string DocumentPath { get; set; }

        /// <summary>
        /// Get or set the Creation date
        /// </summary>
        [DataMember]
        public DateTime CreatedOn { get; set; }

        /// <summary>
        /// Get or set the User that create the version
        /// </summary>
        [DataMember]
        public string CreatedBy { get; set; }

        /// <summary>
        /// Get or set the User that create the version
        /// </summary>
        [DataMember]
        public long OwnerId { get; set; }

        #endregion  

        #region Constructors
        
        public VersioningItem()
        {
            this.VersionId = 0;
            this.Major = 0;
            this.Minor = 0;
            this.Author = string.Empty;
            this.PhotoCredit = string.Empty;
            this.Note = string.Empty;
            this.CreatedBy = string.Empty;
            State = VersionState.Checkin;
        }

        /// <summary>
        /// Only for error
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public VersioningItem(string errorMessage, Exception applicationException = null)
            : base(errorMessage, applicationException)
        {
        }


        #endregion
    }
}

